package com.sicheng.lc.周赛.分类.模拟;

import java.util.Arrays;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/6/19 17:14
 */
@SuppressWarnings("all")
public class 格点数目 {
    int n = 320;
    int d = 100;
    boolean[][] st = new boolean[n][n];

    public int countLatticePoints(int[][] circles) {
        for (int[] circle : circles) {
            build(circle[0], circle[1], circle[2]);
        }

        int cnt = 0;
        for (boolean[] booleans : st) {
            for (boolean ok : booleans) {
                if (ok)
                    cnt++;
            }
        }
        return cnt;
    }

    void build(int x0, int y0, int r) {
        int x = x0 + d;
        int y = y0 + d;
        for (int i = 0; i <= r; i++) {
            Arrays.fill(st[x + i], y - r + i, y + r - i + 1, true);
            Arrays.fill(st[x - i], y - r + i, y + r - i + 1, true);
            for (int j = y - r; j <= y - r + i - 1; j++) {
                if (i * i + (y - j) * (y - j) <= r * r) {
                    st[x + i][j] = true;
                    st[x + i][y - j + y] = true;
                    st[x - i][j] = st[x + i][j];
                    st[x - i][y - j + y] = st[x + i][y - j + y];
                }
            }
        }
    }

    public static void main(String[] args) {
        格点数目 solution = new 格点数目();
        int[][] circles = {{2, 2, 2}, {3, 4, 1}};
        System.out.println(solution.countLatticePoints(circles));
    }
}
